import {get, post} from "@/net";
import {ElMessage} from "element-plus";

const getForumTypes = (success) => {
    get('api/forum/types', success);
}

const getForumTopics = (tid, success) => {
    get(`api/forum/topic?tid=${tid}`, success);
}

const getForumInteract = (tid, type, topic, message) => {
    get(`api/forum/interact?tid=${tid}&type=${type}&state=${!topic[type]}`, () => {
        topic[type] = !topic[type]
        if (topic[type])
            ElMessage.success(`${message}成功`)
        else
            ElMessage.success(`已取消${message}`)
    })
}

const postForumUpdateTopic = (data, success) => {
    post('api/forum/update-topic', data, success);
}

const getForumComments = (tid, page, success) =>
    get(`api/forum/comments?tid=${tid}&page=${page}`, success);

const getDeleteForumComment = (id, success) =>
    get(`api/forum/delete-comment?id=${id}`, success)

const getForumTopTopics = (success) =>
    get('api/forum/top-topic', success)

const getForumTopicList = (page, type, success) => {
    get(`api/forum/list-topic?page=${page}&type=${type}`, success)
}

const getForumCollects = (success) =>
    get('api/forum/collects', success)

const getDeleteForumCollect = (tid, success) =>
    get(`api/forum/interact?tid=${tid}&type=collect&state=false`, success);

const postCreateForumTopic = (data, success) =>
    post('api/forum/create-topic', data, success);

const postAddForumComment = (data, success) =>
    post('api/forum/add-comment', data, success);

export {
    getForumTypes,
    getForumTopics,
    getForumInteract,
    getForumCollects,
    getForumComments,
    getForumTopTopics,
    getForumTopicList,
    getDeleteForumComment,
    getDeleteForumCollect,
    postForumUpdateTopic,
    postCreateForumTopic,
    postAddForumComment,
}